<%-- 
    Document   : CartPage
    Created on : Nov 22, 2012, 10:50:15 PM
    Author     : vupttse
--%>


<%@page import="assignment2.stub.Order"%>
<%@page import="assignment2.data.Products"%>
<%@page import="assignment2.stub.ProductsTbl_Stub"%>
<%@page import="assignment2.stub.ProductsTbl_Stub"%>
<%@page import="java.util.List"%>
<%@page import="java.util.Iterator"%>

<%@page import="java.util.Collection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link href="css/modern.css" rel="stylesheet">
        <link href="css/modern-responsive.css" rel="stylesheet">
        <link href="css/site.css" rel="stylesheet" type="text/css">

        <script src="js/jquery-1.8.2.min.js"></script>
        <script src="js/google-analytics.js"></script>
        <script src="js/github.info.js"></script>
        <script src="js/sharrre/jquery.sharrre-1.3.4.min.js"></script>
        <script src="js/carousel.js"></script>
        <script src="js/dropdown.js"></script>
        <script src="js/slider.js"></script>
        <script src="js/hover.js"></script>
        <script src="js/pagecontrol.js"></script>
        <script src="js/accordion.js"></script>
    <body>
        <div class="page">
            <jsp:include page="Navigation.jsp"></jsp:include>
            <div class="page-region">
                <div class="page-region-content" style="min-height: 400px"> 
                    <h1 class="fg-color-blue">Cart Details:</h1>
                    <div class="span12" style="margin-left: 20px; padding-left: 10px;padding-top: 10px">                        
                        <div class="grid">
                            <div class="row">
                                <%
                                    float total = 0;
                                    try {
                                        List<Order> orders = (List<Order>) session.getAttribute("orders");
                                        if (orders == null) {
                                            response.sendRedirect("ViewProduct.jsp");
                                        }
                                        if (!orders.isEmpty()) {%>
                                <a href="CartPage.jsp"><img src="images/cart.jpg" height="300px" width="300px"></a>
                                <table class="hovered span7 border-color-blue"> 
                                    <tr>
                                        <td>Product ID</td>
                                        <td>Name</td>
                                        <td>Price(VND)</td>
                                        <td>Amount</td>
                                        <td>Value(VND)</td>
                                    </tr>                           

                                    <%
                                        Iterator<Order> iter = orders.iterator();

                                        while (iter.hasNext()) {
                                            Order entity = iter.next();
                                            ProductsTbl_Stub productsTbl_Stub = new ProductsTbl_Stub();
                                            Products proEntity = productsTbl_Stub.findByID(entity.getProductId());
                                            total += proEntity.getUnitPrice() * entity.getQuantity();

                                    %>
                                    <tr>
                                        <td><%= proEntity.getProductID()%></td>
                                        <td><%= proEntity.getProductName()%></td>
                                        <td><%= proEntity.getUnitPrice()%></td>
                                        <td><%= entity.getQuantity()%></td>
                                        <td><%= proEntity.getUnitPrice() * entity.getQuantity()%></td>
                                    </tr>


                                    <% }
                                    %>
                                    <tr>
                                        <td colspan="4" align="right">Total:</td>
                                        <td><%= total%></td>
                                    </tr>
                                </table>
                                <%
                                    Object ob = session.getAttribute("currentUser");
                                    if (ob != null) {
                                %>
                                <a class="button" href="CustomerCheckOut.jsp">Check out!</a>
                                <a class="button" href="ViewProduct.jsp">Continue shopping!</a>
                                <%} else {%>
                                <a class="button" href="CheckOutAnonymous.jsp">Check out!</a>
                                <a class="button" href="ViewProduct.jsp">Continue shopping!</a>
                                <%}%>
                                <%} else {
                                %>
                                <h3 style="color: red">Cart is empty!</h3>
                                <%                            }
                                } catch (Exception e) {%>
                                <h3><%= "Error: " + e.getMessage()%></h3>
                                <% }%>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <%@include  file="footer.html" %>
        </div>
    </body>
</html>
